package cn.qvtu.game.controller;

import cn.qvtu.game.model.BackGround;
import cn.qvtu.game.model.Enemy;

public class EnemyController implements Runnable
{
    private Enemy enemy;
    private BackGround background;
    public EnemyController(Enemy enemy,BackGround background)
    {
        this.background=background;
        this.enemy=enemy;
    }
    public void run()
    {
        while(true)
        {
            try
            {
                if ((enemy.getStatus() == 1 || enemy.getStatus() == -1))
                {
                    enemy.setStatus(-2);//站立状态修改成左跑状态
                }
                if (enemy.getX() <= -100)
                {
                    enemy.setStatus(2);//x坐标小于等于-100，修改为右跑
                }
                if (enemy.getX() >= 550)
                {
                    enemy.setStatus(-2);//x坐标大于等于550，修改为左跑
                }
                if(background.getPerson()!=null)
                {
                    int enemyW=150;
                    int personW=80;
                    if((enemy.getX()+enemyW>background.getPerson().getX())&&(background.getPerson().getX()+personW>enemy.getX()))
                    {
                        System.out.println("你被攻击到了");
                        background.setHp(background.getHp()-50);
                    }
                }
                else
                {
                    System.out.println('s');
                }
                Thread.sleep(500);
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }
        }
    }
}
